﻿using Modules;
using AutoMapper;
using PmSoft;
using Modules.Project;

namespace ManagementApi.Models.System;

public class SysEarlyWarningDto : SysEarlyWarning
{
    #region 扩展属性

    //这里自行增加扩展属性
    public string ProjectName { get; set; }

    public string? TenantName { get; set; }

    public string? WarningTypeName { get; set; }

    #endregion 扩展属性
}

public static partial class SysEarlyWarningExceptions
{
    /// <summary>
    /// 项目预警
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    public static SysEarlyWarningDto AsProjectWarningDto(this SysEarlyWarning entity)
    {
        SysEarlyWarningDto dto = new();
        var mapper = ServiceAccessor.GetService<IMapper>();
        mapper.Map(entity, dto);

        #region 扩展属性赋值

        var projectService = ServiceAccessor.GetService<ProjectService>();
        var project = projectService.GetProjectInfo(Convert.ToInt32(entity.ObjectId));
        dto.ProjectName = project?.Name ?? string.Empty;
        dto.TenantName = dto.Tenant.GetDescription();
        dto.WarningTypeName = dto.WarningType.GetDescription();

        #endregion 扩展属性赋值

        return dto;
    }
}